package com.lz.demo11;

import java.util.Arrays;

/**
 * @ClassName TestAnimalShop
 * @Description 测试
 * @Author 2214361854
 * @Date 2022/5/28 15:32
 * @Version 1.0
 */
public class TestAnimalShop {
    public static void main(String[] args) {
        //开始测试
        //1.创建宠物商店对象
        AnimalShop shop = new AnimalShop();
        //2.给宠物店起名字
        shop.shopName = "爱宠宠物店";

        //3.查看宠物店现在所有的宠物
        System.out.println("定义"+shop.shopName+"："+Arrays.toString(shop.animals));

        //4.1创建动物对象--叫小白的3岁的小猫
        Cat cat = new Cat();
        cat.name = "小白";
        cat.age = 3;
        //4.2将第一只创建好的小动物放到数组里
        shop.animals[0] = cat;

        //5.1创建一只叫罗小黑的5岁的猫
        Cat cat1 = new Cat();
        cat1.name = "罗小黑";
        cat1.age = 5;
        //5.2将第二只创建好的小动物放到数组里
        shop.animals[1] = cat1;

        //6.1创建一只叫旺财的4岁的狗
        Dog dog = new Dog();
        dog.name = "旺财";
        dog.age = 4;
        //6.2将第三只创建好的小动物放到数组里
        shop.animals[2] = dog;

        //7.1创建一只叫银子的100岁的鸟
        Bird bird = new Bird();
        bird.name = "银子";
        bird.age = 100;
        //7.2将第四只创建好的小动物放到数组里
        shop.animals[3] = bird;

        //8.1创建一只叫大米的7岁的狗
        Dog dog1 = new Dog();
        dog1.name = "大米";
        dog1.age = 7;
        //8.2将第五只创建好的小动物放到数组里
        shop.animals[4] = dog1;

        //9.通过遍历数组，查看所有的动物的名字与年龄
        for (int i = 0; i < 5; i++) {
            System.out.println(shop.animals[i].name + shop.animals[i].age);
        }

        //10.调用动物们各自的功能
        shop.animals[0].eat();//小猫爱吃小鱼干~重写后的功能
        shop.animals[4].eat();//小动物Animal吃啥都行~继承自父类的功能

        //11.调用查询动物的方法
        Animal animal = shop.query(2);
        System.out.println(animal.name + animal.age);

        //12.调用购买动物的方法
        shop.buy(cat1);
        shop.buy(bird);
    }
}